package com.qyy.remotemonitor.common.ui;

import android.app.Service;
import android.content.Intent;

import com.qyy.remotemonitor.MyApplication;
import com.qyy.remotemonitor.common.di.DaggerServiceCommonComponent;
import com.qyy.remotemonitor.common.di.ServiceCommonComponent;
import com.qyy.remotemonitor.common.di.interfaces.DiServiceSupport;
import com.wang.android.library.di.EasyBasePresenter;
import com.wang.android.library.di.modules.ServiceModule;
import com.wang.android.library.ui.IFBaseView;

import javax.inject.Inject;


public abstract class BaseService<P extends EasyBasePresenter> extends Service
        implements DiServiceSupport,IFBaseView
{
    @Inject
    protected P presenter;


    @Override
    public void onCreate()
    {
        super.onCreate();
        initInject();
        register();
        if(presenter != null)
        {
            presenter.attachView(this);
            presenter.setContext(this);
        }
    }

    @Override
    public void onDestroy()
    {
        super.onDestroy();
        unregister();
    }

    @Override
    public abstract void initInject();

    public abstract void initTodo();
    @Override
    public ServiceCommonComponent getServiceComponent() {
        return DaggerServiceCommonComponent.builder()
                .appCommonComponent(((MyApplication) getApplication()).getAppCommonComponent())
                .serviceModule(getServiceModule())
                .build();
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId)
    {
        initTodo();
        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public ServiceModule getServiceModule() {
        return new ServiceModule(this);
    }


    public P getPresenter()
    {
        return presenter;
    }

}
